layui.use(['form','layer','laydate'], function() {

    var $ = layui.$
        ,form = layui.form
        ,laydate = layui.laydate;

    //去程航班日期
    laydate.render({
        elem: '#flight-date'
        ,type: 'date'
        ,range: ['#flight-start', '#flight-end']
        //,rangeLinked: true // 是否开启日期范围选择时的区间联动标注模式
        //,value: ['2022-05-01', '2022-06-01']
        //,value: '2022-05-01 - 2022-06-01'
    });

    //范围选择2
    laydate.render({
        elem: '#flight-date'
        ,type: 'date'
        ,range: ['#flight-start-back', '#flight-end-back']
        //,rangeLinked: true // 是否开启日期范围选择时的区间联动标注模式
        //,value: ['2022-05-01', '2022-06-01']
        //,value: '2022-05-01 - 2022-06-01'
    });

    //销售日期
    laydate.render({
        elem: '#sale-date'
        ,type: 'date'
        ,range: ['#sale-start', '#sale-end']
        //,rangeLinked: true // 是否开启日期范围选择时的区间联动标注模式
        //,value: ['2022-05-01', '2022-06-01']
        //,value: '2022-05-01 - 2022-06-01'
    });


    // 订位
    form.on('radio(IsBooking)',function (data){

        if(data.value == "") {

            $('#BookingThreshold').show();
        } else {
            $('#BookingThreshold').hide();
        }
        //alert(data);
    });

    //是否紧张位置过滤
    form.on('radio(IsShortageFilter)',function (data) {

        if(data.value == 'T') {
            $('#ShortageFilterCount').show();
        } else {
            $('#ShortageFilterCount').hide();
        }
    });

    //是否PATA
    form.on('radio(NeedPATA)',function (data) {
        if(data.value == 'T'){
            $('.pata-item').show();
        } else {
            $('.pata-item').hide();
        }
    });

    //是否共享
    form.on('radio(IsShareFlight)',function (data) {

        if(data.value == 'T') {
            $('#IsValidCarrierAirline').show();
        } else {
            $('#IsValidCarrierAirline').hide();
        }

    });

    //单程往返
    form.on('radio(FlightWay)',function (data){
        if(data.value == 'S') {
            $('.go-item').show();
            $('.back-item').hide();
        } else {
            $('.go-item').hide();
            $('.back-item').show();
        }
    })

    /**
     * 去程班期
     */
    $('#flight-week-all').on('click',function () {

        $('input[name="Days[]"]').each(function () {
            this.checked = true;
        });

        form.render('checkbox'); //刷新
    });

    $('#flight-week-invert').on('click',function () {

        $('input[name="Days[]"]').each(function () {
            this.checked = !this.checked;
        });

        form.render('checkbox'); //刷新
    })

    /**
     * 返程班期
     */
    $('#flight-week-all-back').on('click',function () {

        $('input[name="BackDays[]"]').each(function () {
            this.checked = true;
        });

        form.render('checkbox'); //刷新
    });

    $('#flight-week-invert-back').on('click',function () {

        $('input[name="BackDays[]"]').each(function () {
            this.checked = !this.checked;
        });

        form.render('checkbox'); //刷新
    })

    /**
     * 销售周期
     */
    $('#sale-week-all').on('click',function () {

        $('input[name="SaleDays[]"]').each(function () {
            this.checked = true;
        });

        form.render('checkbox'); //刷新
    });

    $('#sale-week-invert').on('click',function () {

        $('input[name="SaleDays[]"]').each(function () {
            this.checked = !this.checked;
        });

        form.render('checkbox'); //刷新
    })

    //乘客人数
    form.on('checkbox(HideSales)',function (data){

        if(data.elem.checked == true) {

            $('#passengers-num').show();
        } else {
            $('#passengers-num').hide();
        }
        //alert(data);
    });

    //身份证限制
    form.on('radio(IDLimit)',function (data){

        if(data.value == 'T') {

            $('#IDCardList').show();
        } else {
            $('#IDCardList').hide();
        }
        //alert(data);
    });

    //库存类型
    form.on('radio(InventoryType)',function (data) {
        if(data.value == 'FIX') {

            $('#IsReturnRefundInventory').show();
        } else {
            $('#IsReturnRefundInventory').hide();
        }
    })

    //竞价空间
    form.on('radio(BidType)',function (data) {
        if(data.value == 0) {

            $('.BiddingSpace_Money').show();
            $('.BiddingSpace_Percentage').hide();
        } else {
            $('.BiddingSpace_Money').hide();
            $('.BiddingSpace_Percentage').show();
        }
    })

    //库存类型
    $("#TicketInventory").bind('blur', function(event) {
        var inputData = $("#TicketInventory").val();
        $('input[name="LeftInventory"]').val(inputData);
    });
})